package com.cskaoyan.controller.wx;

import com.cskaoyan.bean.MarketCollect;
import com.cskaoyan.bean.common.BaseRespVo;
import com.cskaoyan.bean.common.CommonData;
import com.cskaoyan.bean.vo.wx.collect.AddOrDeleteVo;
import com.cskaoyan.bean.vo.wx.collect.CollectListVo;

import com.cskaoyan.service.wx.WxCollectService;
import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.Mapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.Map;


/**
 * 商品收藏
 * url:/wx/collect/list?type=0&page=1&limit=10
 *
 * @Author: zhang
 * @Date: 2022/11/22 23:07
 * @Since: jdk1.8
 */
@RestController
@RequestMapping("wx/collect")
public class WxCollectController {
    @Autowired
    WxCollectService wxCollectService;

    /**
     * 列出所有收藏的商品
     *
     * @param type  类型
     * @param page  页码
     * @param limit 每页显示几个
     * @return 收藏的商品
     */

    @RequestMapping("/list")
    public BaseRespVo<CommonData<CollectListVo>> list(Integer type, Integer page, Integer limit) {
        CommonData<CollectListVo> data = wxCollectService.list(type, page, limit);
        return BaseRespVo.ok(data);
    }

    /**
     * @author zjq
     * 没有做参数校验
     * @date 2022/11/23 14:09
     */
    @RequestMapping("/addordelete")
    public BaseRespVo<Object> addordelete(@RequestBody Map map) {
        Integer valueId = (Integer) map.get("valueId");
        wxCollectService.addOrDelete(valueId);
        return BaseRespVo.ok(new AddOrDeleteVo(0, valueId));
    }
}
